package com.gxa.order.service.impl;/*
 *Created by${妄也} on 2022/10/6
 */

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.common.utils.FileUtils;
import com.gxa.common.utils.UploadController;
import com.gxa.order.pojo.AccommodationComments;

import com.gxa.order.pojo.Refund;
import com.gxa.order.service.accommodationServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;

@Service
public class accommodationServerImpl implements accommodationServer {
    @Autowired(required = false)
    private com.gxa.order.mapper.accommodationMapper accommodationMapper;

    @Override
    public JsonResult findcomments(HashMap map) {
        JsonResult pageResult = new JsonResult();
//        分页操作
        Integer currentPage = Integer.parseInt(map.get("currentPage").toString());
        Integer pageSize = Integer.parseInt(map.get("pageSize").toString());
        int current = (currentPage-1)*pageSize;
        System.out.println(current);
        map.put("currentPage",current);
        map.put("pageSize",pageSize);

        try{

        }catch (Exception e){

        }
        List<AccommodationComments> accommodationCommentsLIst =accommodationMapper.findcomments(map);
        Integer count=0;
        if (accommodationCommentsLIst.size()<1){
            count=0;
        }else{
            count=accommodationMapper.findcount(map);
        }


        pageResult.setCode(200);
        pageResult.setCount(count);
        pageResult.setData(accommodationCommentsLIst);
        pageResult.setMsg("查询成功");

        return pageResult;
    }
//增加评论
    @Override
    public R addcomments(AccommodationComments accommodationComments) {

        UploadController uploadController = new UploadController();
        if (accommodationComments.getPictureTP1()!=null){
            HashMap PictureTP1 = (HashMap)  uploadController.upload(accommodationComments.getPictureTP1());;
            accommodationComments.setPicture1(PictureTP1.get("url").toString());
        }
        if (accommodationComments.getPictureTP2()!=null){
            HashMap PictureTP2 = (HashMap)  uploadController.upload(accommodationComments.getPictureTP2());;
            accommodationComments.setPicture2(PictureTP2.get("url").toString());
        }
        if (accommodationComments.getPictureTP3()!=null){
            HashMap PictureTP3 = (HashMap)  uploadController.upload(accommodationComments.getPictureTP3());;
            accommodationComments.setPicture3(PictureTP3.get("url").toString());
        }
        //设置时区
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        TimeZone.setDefault(timeZone);

        //获取当前时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        accommodationComments.setStartDate(format);

        int insert = accommodationMapper.addcomments(accommodationComments);
        R r = new R();
        r.setCode(200);
        r.setMsg("增加成功");
        return r;
    }

    @Override
    public R updatacomments(String id, String status) {
        UpdateWrapper<AccommodationComments> accommodationCommentsUpdateWrapper = new UpdateWrapper<>();
        accommodationCommentsUpdateWrapper.eq("id",Integer.parseInt(id));

        AccommodationComments accommodationComments = new AccommodationComments();
        accommodationComments.setStatus(Long.parseLong(status));

        accommodationMapper.update(accommodationComments,accommodationCommentsUpdateWrapper);
        R r = new R();
        r.setCode(200);
        r.setMsg("修改成功");
        return r;

    }


}
